import { verify } from "jsonwebtoken";
import { ObjectId } from "mongodb";
import { BaseServer } from "tsrpc";
import { Global } from "../Global";
import { ServiceType } from "../shared/protocols/serviceProto";

export async function needRole(server: BaseServer<ServiceType>) {
    server.flows.preApiCallFlow.push(async (call) => {
        const conf = call.service.conf
        if (conf?.needRole) {
            const role = call.currentUser.role
            if (role !== conf.needRole) {
                call.error('没有权限')
                return null
            }
        }
        else {
            // console.log("no role");
        }

        return call
    })
}

export async function needRoleWs(server: BaseServer<ServiceType>) {
    return
}